package org.fuys.coder.application.interceptor;

import org.fuys.coder.common.entity.Result;
import org.fuys.coder.common.exception.vertify.PermissionException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.common.interceptor
 * @className: GlobalExceptionHandler
 * @author: WangJing
 * @description: 全局异常处理器
 * @date: 2024/8/10 12:00
 * @version: 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(PermissionException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ResponseEntity<Result> handlePermissionException(PermissionException exception){
        return new ResponseEntity<>(Result.error(exception.getMsg()),HttpStatus.FORBIDDEN);
    }
}
